package com.decade.controller;

import com.decade.global.R;
import com.decade.global.Result;
import com.decade.pojo.Door;
import com.decade.service.DoorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class DoorController {

    @Autowired
    private DoorService doorService;

    @RequestMapping("index")
    public  String toIndex(){
        return "/index.jsp";
    }

    //添加
    @ResponseBody
    @RequestMapping(value = "addDoor",produces = "application/json;charset=utf-8")
    public String addDoor(){
        Door door = new Door();
        door.setName("一品斋");
        door.setAddr("南宁");
        door.setStatus(1);
        door.setTel("1360000000");
        doorService.addDoor(door);
        return "插入成功";
    }

    //查询所有门店
    @ResponseBody
    @RequestMapping(value = "queryDoorList")
    public Result queryDoorList(){
        List<Door> list = doorService.queryDoorList();
        list.forEach(door -> System.out.println(door));
        return R.success("你好啊");
    }

    //按id查询
    @ResponseBody
    @RequestMapping(value = "queryDoorById")
    public String queryDoorById(Integer id){
        Door door = doorService.queryDoorById(id);
         System.out.println(door);
        return "成功";
    }

    //模糊查询
    @ResponseBody
    @RequestMapping(value = "queryDoorLike")
    public String queryDoorLike(Door door){
        List<Door> list = doorService.queryDoorLike(door);
        list.forEach(d -> System.out.println(d));
        return "成功";
    }

    //删除门店
    @ResponseBody
    @RequestMapping(value = "deleteDoorById")
    public String deleteDoorById(Integer id){
        int row = doorService.deleteDoorById(id);
        System.out.println(row);
        return "成功";
    }

    //根据door的id修改
    @ResponseBody
    @RequestMapping(value = "updateDoorById")
    public String updateDoorById(Door door){
        int row = doorService.updateDoorById(door);
        System.out.println(row);
        return "成功";
    }
}
